﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace DealerJudge.Core
{
    public class ConfigManager : IConfigManager 
    {
        private string connectionStringKey = "ConnectionString";
        private string connectionStringExceptionMessage = "Entry with key: {0} not found in config file.";

        public string GetConnectionString()
        {
            //return ReadConfigValue(connectionStringKey);
            //return @"Data Source=C:\DealerJudge\SVN\DealerJudgeMaster\DealerJudge.Data\Database\DealerJudgeDb.sdf;Persist Security Info=False;";
            return @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\DealerJudge\SVN\DealerJudgeMaster\DealerJudge.Data\Database\DealerJudgeDatabase.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
        }

        private string ReadConfigValue(string key)
        {
            if (ConfigurationManager.AppSettings[key] == null)
            {
                throw new DealerJudgeException(string.Format(connectionStringExceptionMessage, key));
            }

            string value = ConfigurationManager.AppSettings[key];

            return value;
        }       
    }
}
